package com.rongkang.interview.juc.multithreading;

import java.util.concurrent.*;

/**
 * @Description:
 * @author: 荣康
 * @date: 2021/12/14
 */
public class ThreadPoolDemo {
    public static void main(String[] args) {
        System.out.println(Runtime.getRuntime().availableProcessors());//先查询cpu是几核的
        //拒绝策略，直接抛出异常
        ExecutorService executorService = new ThreadPoolExecutor(2,
                5,
                1L,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<Runnable>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy());
        try {
            for (int i = 0; i <10;i++) {
                final  int temp = i;
                executorService.execute(()->{
                    System.out.println(Thread.currentThread().getName() +"\t  "+ temp+"办理业务");
                });
            }
        } finally {
            executorService.shutdown();
        }

    }
}

